ostree: check g_setenv return value
authorLuca BRUNO <luca.bruno@coreos.com>
Mon, 10 Jan 2022 10:22:28 +0000 (10:22 +0000)
committerLuca BRUNO <luca.bruno@coreos.com>
Mon, 10 Jan 2022 13:33:36 +0000 (13:33 +0000)
This adds proper return-value checks on g_setenv calls.
It fixes a static analysis warning highlighted by Coverity.

src/libostree/ostree-sepolicy.c
src/ostree/ot-main.c
tests/libostreetest.c
tests/test-gpg-verify-result.c
tests/test-rollsum-cli.c
tests/test-varint.c

index d8ff35cb7190eab129998dcc6f643d276d181eed..0fed645769641371ab0caae0a426bb68adaba8d9 100644 (file)
@@ -422,7 +422,10 @@ initable_init (GInitable     *initable,
     {
       const char *policy_rootpath = gs_file_get_path_cached (policy_root);
 
-      g_setenv ("LIBSELINUX_DISABLE_PCRE_PRECOMPILED", "1", FALSE);
+      /* TODO(lucab): get rid of this setenv(), it may be unsafe in a multi-thread context. */
+      if (!g_setenv ("LIBSELINUX_DISABLE_PCRE_PRECOMPILED", "1", FALSE))
+        return glnx_throw (error, "Failed to set environment variable LIBSELINUX_DISABLE_PCRE_PRECOMPILED");
+
       if (selinux_set_policy_root (policy_rootpath) != 0)
         return glnx_throw_errno_prefix (error, "selinux_set_policy_root(%s)", policy_rootpath);
 
index 8ee73038295bd673270d4b266f16c9ea4bda921d..b72fa9d42d5e759091efdd847dd6e7f50a27ca01 100644 (file)
@@ -253,7 +253,11 @@ ostree_run (int    argc,
   int in, out;
 
   /* avoid gvfs (http://bugzilla.gnome.org/show_bug.cgi?id=526454) */
-  g_setenv ("GIO_USE_VFS", "local", TRUE);
+  if (!g_setenv ("GIO_USE_VFS", "local", TRUE))
+    {
+      (void) glnx_throw (res_error, "Failed to set environment variable GIO_USE_FVS");
+      return 1;
+    }
 
   g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, message_handler, NULL);
 
index d5671a1eabd650ea797242601c64c05c55912f67..08abb9f11ec21a540f56176b21edf18a0ebc083c 100644 (file)
@@ -155,7 +155,8 @@ ot_test_setup_sysroot (GCancellable *cancellable,
     }
 
   /* Make sure deployments are mutable */
-  g_setenv ("OSTREE_SYSROOT_DEBUG", buf->str, TRUE);
+  if (!g_setenv ("OSTREE_SYSROOT_DEBUG", buf->str, TRUE))
+    return glnx_null_throw (error, "Failed to set environment variable OSTREE_SYSROOT_DEBUG");
 
   g_autoptr(GFile) sysroot_path = g_file_new_for_path ("sysroot");
   return ostree_sysroot_new (sysroot_path);
index d49224ec45dd9e7ae83d4d0058b7ab724b844698..8485b8883e3f8156979a6820c5ddf083770c7afc 100644 (file)
@@ -78,7 +78,8 @@ test_fixture_setup (TestFixture *fixture,
    * certificates for certain test cases. */
 
   homedir = g_test_build_filename (G_TEST_DIST, "tests/gpg-verify-data", NULL);
-  g_setenv ("GNUPGHOME", homedir, TRUE);
+  gboolean is_ok = g_setenv ("GNUPGHOME", homedir, TRUE);
+  g_assert (is_ok == TRUE);
 
   result = g_initable_new (OSTREE_TYPE_GPG_VERIFY_RESULT,
                            NULL, &local_error, NULL);
index 44e3390c60c186b94c7aa6a681aea5b3d548b9bd..2cf730d3e92547727e62cc47deecf1b0c283ad0d 100644 (file)
@@ -35,7 +35,8 @@ main (int argc, char **argv)
   OstreeRollsumMatches *matches;
   GMappedFile *mfile;
 
-  g_setenv ("GIO_USE_VFS", "local", TRUE);
+  gboolean is_ok = g_setenv ("GIO_USE_VFS", "local", TRUE);
+  g_assert (is_ok == TRUE);
 
   if (argc < 3)
     return 1;
index e86c008f00b575252ccc373a00493b9b5e14c29d..3fea805e698ebd9a05783aa19a7090e8e4eb9edd 100644 (file)
@@ -58,7 +58,8 @@ int
 main (int argc, char **argv)
 {
 
-  g_setenv ("GIO_USE_VFS", "local", TRUE);
+  gboolean is_ok = g_setenv ("GIO_USE_VFS", "local", TRUE);
+  g_assert (is_ok == TRUE);
 
   g_test_init (&argc, &argv, NULL);